<template>
    <div>
      <table-expand
        ref="table"
        :columns="columns"
        :data="basicData"
        :loading="loading"
        :config="config"
        :pageSizeOpts="pageSizeOpts"
        :pageNavigation="pageNavigation"
        :queryFormItem="queryFormItem"
        :collapseFormItem="collapseFormItem"
        :additionalAction="additionalAction"
        @loadPage="loadPage"
        @handleCreate="handleCreate"
        @handleDetail="handleDetail"
        @handleEdit="handleEdit"
        @handleDelete="handleDelete"
        @handleDeleteMultiple="handleDeleteMultiple"
        @handleSearch="handleSearch"
        @handleReset="handleReset"
      ></table-expand>
      <new-add-modal
        v-bind="addNewPanel"
        :modelType="modelType"
        :columns="formColumns"
        :rules="rules"
        @submit="handleNewAddSubmit"
      ></new-add-modal>
      <edit-modal
        v-bind="editPanel"
        :modelType="modelType"
        :columns="formColumns"
        :rules="rules"
        @submit="handleEditSubmit"
      ></edit-modal>
      <read-modal
        v-bind="readPanel"
        :modelType="modelType"
        :columns="columns"
        :rules="rules"
      ></read-modal>
    </div>
</template>

  <script>
    import tableExpand from '@/pages/components/tableExpand.vue';
    import newAddModal from '@/pages/components/newAddModal.vue';
    import editModal from '@/pages/components/editModal.vue';
    import readModal from '@/pages/components/readModal.vue';
    import { typeClassName } from '@/pages/config/classNameMap';
    import logicDictionaryMixin from '@/pages/components/mixins/logicDictionaryMixin'
    import columnsMixin from './config'
    export default {
        components: { tableExpand, newAddModal, editModal, readModal },
        name: 'position',
        mixins: [logicDictionaryMixin,columnsMixin],
        data () {
            return {
                classObject: null, // 单个职级实例
                collectionObject: null, // 所有职级实例
                className: typeClassName['position'].className,
                type: typeClassName['position'].type,
                modelType: typeClassName['position'].modelType,
                levelClassObject: null, // 职级级别实例
                levelClassName: typeClassName['positionLevel'].className,
                levelType: typeClassName['positionLevel'].type,
                levelModelType: typeClassName['positionLevel'].modelType,
                positionLevelOptions: [],
                addNewPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2
                },
                editPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                readPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                rules: {
                    sf_code: [
                        { required: true, message: '不能为空', trigger: 'blur' },
                        { max: 50, message: '编码最大长度不可超过50', trigger: 'blur' }
                    ],
                    sf_name: [
                        { required: true, message: '不能为空', trigger: 'blur' },
                        { max: 200, message: '名称最长长度不可超过200', trigger: 'blur' }
                    ],
                    remark: [
                        { max: 500, message: '描述最长长度不可超过500', trigger: 'blur' }
                    ]
                },
                loading: false,
                config: {
                    search: true,
                    addButton: true,
                    batchDeleteButton: true,
                    tableSizeIcon: true,
                    fullscreenIcon: true,
                    refreshIcon: false,
                    columnSettingIcon: true,
                    action: true,
                    additionalAction: false
                },
                pageSizeOpts: [10, 30, 50, 100],
                pageNavigation: { total: 0, pageSize: 10, pageNumber: 1 },
                basicData: []
            };
        },
        computed: {
            additionalAction () {
                return [];
            }
        },
        beforeMount () {
            this.collectionObject = this.$modelObject.create(`${this.modelType}Collection`);
            this.classObject = this.$modelObject.create(this.modelType);
            this.levelClassObject = this.$modelObject.create(this.levelModelType);
            this.loadPage(this.pageNavigation, null);
            this.getPositionLevel();
        },
        mounted () {},
        methods: {
            getPositionLevel () {
                let filter = {
                    className: this.levelClassName,
                    type: this.levelType
                }
                let newFilter = '';
                if (this.tools.isReal(filter)) {
                    newFilter = this.levelClassObject.util.getFilter(filter);
                }
                return this.levelClassObject.query(newFilter).then((flag) => {
                    if (flag) {
                        this.positionLevelOptions = this.levelClassObject.record.hier[0].basic.map(d => {
                            return {
                                value: d.title,
                                label: d.title
                            }
                        });
                    } else {
                        return false;
                    }
                });
            }
        }
    };
  </script>
  <style scoped lang="scss"></style>
